package com.wf.demo.job.beidou;

import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.util.Random;

/**
 * @Auther: wf
 * @Date: 2020/5/28 19:35
 * @Description:
 */

public class TxsqMessage {
    private static final String SEND_TXSQ_HEAD="24 54 58 53 51";      //$TXSQ

    private static final int FIRM_SIZE= 18;                           //包固定长度为18个字节

    private static  byte PAGE_LENTH_HIGH;                             // 包长度高位，先传高位，再传低位

    private static  byte PAGE_LENTH_LOW;                              //包长度低位

    private static String SRC_USER_ADDR;                              //源用户地址，在这里是北斗指挥机卡号，也可以直接为00 00 00

    private static final  int TRANSFER_FORMAT=0x46;                   //00为汉字，0x46为混发

    private static String DST_USER_ADDR;                              //目的用户地址，要控制的北斗终端卡号

    private static  byte PAYLOAD_LENTH_HIGH;                          // 电文净荷长度高位，先传高位，再传低位

    private static  byte PAYLOAD_LENTH_LOW;                           //电文净荷长度低位

    private static  final int IF_ANSER=0x00;                          //是否应答，固定为00

    private static  final int FIRM_START=0xA4;                        //电文内容开头固定为A4

    private static  String PAYLOAD;                                   //电文内容

    private static  byte XOR_CHECKSUM;                                //校验和


    private static  String creatTxxx(PayLoadData payLoadData){
        Random r = new Random(1);
            int[] txxx =new int [100];
            int ran1=r.nextInt(10);
            int ran2=r.nextInt(5);
            int beidouId=82550+ran1+ran2*100000;
            txxx[0]=0x24;
            txxx[1]=0x54;
            txxx[2]=0x58;
            txxx[3]=0x58;
            txxx[4]=0x58;

            txxx[5]=0x00;
            txxx[6]=0x2B;   //总共长度为43

        txxx[7]=0x00;
        txxx[8]=0x00;
        txxx[9]=0x00;

        txxx[10]=0x60;  //信息类别

        txxx[11]=(byte)((beidouId >> 16) & 0xFF); //发送方地址
        txxx[12]=(byte)((beidouId >> 8)& 0xFF);
        txxx[13]=(byte)(beidouId & 0xFF);

        txxx[14]=0x00;  //时间
        txxx[15]=0x00;

        txxx[16]=0x00;
        txxx[17]=0xB8;   //长度  23*8=184

        txxx[41]=0x00;  //CRC
        txxx[42]=0xF0;  //校验码
        return  txxx.toString();
    }

}
